home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / vap / sap.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  5KB  |  152 lines

  1. /*****************************************************************************
  2.  *
  3.  * Program Name:  SAMPLE.VAP
  4.  *
  5.  * Filename:      sap.c
  6.  *
  7.  * Version:          1.0
  8.  *
  9.  * Programmers:      Bryan Sparks
  10.  *
  11.  * Files used:      comm.h
  12.  *
  13.  * Comments:      This is a "plug-in" sap module to do service advertising.
  14.  *
  15.  ****************************************************************************/
  16. #include "comm.h"
  17.  
  18. /* We will keep this pointer around so as to keep track of the */
  19. /* oscillating ECB.  We will need to know where it is later so we */
  20. /* can cancel the event associated with that ECB. */
  21. ECB        *DownECBPointer;
  22.  
  23. void        SAPWaitESRHandler();
  24. void        SAPAdvertiseESRHandler();
  25.  
  26. SAPData        SAPDataEntity;
  27. ECB            SAPECB;
  28. IPXPacket    SAPPacket;
  29.  
  30. void StartSAPOscillationRoutines( ServerName, ServerType, ServerSocket )
  31. char    ServerName[48];
  32. int        ServerType;
  33. unsigned int    ServerSocket;
  34. {
  35.     /* Initialize the variables for the SAP IPXPacket. */
  36.     /* Notice that I broadcast on socket 452h (The SAP Socket) */
  37.     /* You need not have the socket open to send on the socket. */
  38.     SAPPacket.PacketType = (unsigned char)4;
  39.     SAPPacket.PacketLength = IntSwap( sizeof( IPXPacket ) );
  40.     IPXGetInternetworkAddress( (unsigned char *)SAPPacket.Destination.Network );
  41.     memset( SAPPacket.Destination.Node, 0xFF, 6 );
  42.     SAPPacket.Destination.Socket = 0x5204;
  43.  
  44.     /* I initialize the SAP data packet.  See the SAP document for details. */
  45.     SAPDataEntity.InfoType = IntSwap( 2 );
  46.     SAPDataEntity.ServerType = IntSwap( ServerType );
  47.     strcpy( SAPDataEntity.ServerName, ServerName);
  48.     IPXGetInternetworkAddress( (unsigned char *)SAPDataEntity.Address.Network );
  49.     SAPDataEntity.IntermediateNetworks = IntSwap( 1 );
  50.     SAPDataEntity.Address.Socket = ServerSocket;
  51.  
  52.     /* Initialize the ECB. */
  53.     SAPECB.ESRAddress = (char far *)SAPWaitESRHandler;
  54.     SAPECB.InUseFlag = 0;
  55.     SAPECB.FragmentCount = 2;
  56.     SAPECB.ECBSocket = 0x5204;
  57.     memset( SAPECB.ImmediateAddress, 0xFF, 6 );
  58.     SAPECB.FragmentDescriptor[0].Address = (char far *)&SAPPacket;
  59.     SAPECB.FragmentDescriptor[0].Size = sizeof (IPXPacket );
  60.     SAPECB.FragmentDescriptor[1].Address = (char far *)&SAPDataEntity;
  61.     SAPECB.FragmentDescriptor[1].Size = sizeof( SAPData );
  62.  
  63.     IPXSendPacket( &SAPECB );
  64.  
  65. }
  66.  
  67.  
  68. /* These two ESRs require some explanation. */
  69. /* When the IPXSendPacket is done above the ESR SAPWaitESR will be called */
  70. /* This ESR will immediately change the ESR to SAPAdvertiseESR and waits */
  71. /* one minute.  In one minute the SAPAdvertiseESR will be activated and */
  72. /* it will change the ESR to SAPWaitESR and then do a send packet. */
  73. /* These two ESRs will oscillate back and forth thus doing SAP calls. */
  74. void SAPWaitESR( wECB )
  75. ECB        *wECB;
  76. {
  77.     wECB->ESRAddress = (char far *)SAPAdvertiseESRHandler;
  78.     IPXScheduleIPXEvent( 60*18, wECB );        /* Every 60 Seconds */
  79. }
  80.  
  81.  
  82. void SAPAdvertiseESR( wECB )
  83. ECB        *wECB;
  84. {
  85.     wECB->ESRAddress = (char far *)SAPWaitESRHandler;
  86.     IPXSendPacket( wECB );
  87. }
  88.  
  89.  
  90. int StopSAPOscillationRoutines( ServerName, ServerType, ServerSocket )
  91. char    ServerName[48];
  92. int        ServerType;
  93. unsigned int    ServerSocket;
  94. {
  95.     SAPData        wDataEntity;
  96.     ECB            wECB;
  97.     IPXPacket    wPacket;
  98.  
  99.  
  100.     /* First we will cancel the SAP oscillation ESRs. */
  101.     IPXCancelEvent( &SAPECB );
  102.     while (SAPECB.InUseFlag)
  103.         ;
  104.  
  105.     /* Was the event canceled?  FC means yes. */
  106.     if (SAPECB.CompletionCode != 0xFC) 
  107.         return (-1);
  108.  
  109.     /* Now we will send out a IPX packet telling everyone that this */
  110.     /* server is down.  See the SAP document for details. */
  111.     wPacket.PacketType = (unsigned char)4;
  112.     wPacket.PacketLength = IntSwap( sizeof( IPXPacket ) );
  113.     IPXGetInternetworkAddress( (unsigned char *)wPacket.Destination.Network );
  114.     memset( wPacket.Destination.Node, 0xFF, 6 );
  115.     wPacket.Destination.Socket = 0x5204;
  116.  
  117.     /* I initialize the SAP data packet.  See the SAP document for details. */
  118.     /* Tell everyone that I am going down. (Thus the 16 intermediate networks) */
  119.     wDataEntity.InfoType = IntSwap( 2 );
  120.     wDataEntity.ServerType = IntSwap( ServerType );
  121.     strcpy( wDataEntity.ServerName, ServerName);
  122.     IPXGetInternetworkAddress( (unsigned char *)wDataEntity.Address.Network );
  123.     wDataEntity.IntermediateNetworks = IntSwap( 16 );
  124.     wDataEntity.Address.Socket = ServerSocket;
  125.  
  126.     /* Initialize the ECB. */
  127.     wECB.FragmentCount = 2;
  128.     wECB.ECBSocket = 0x5204;
  129.     memset( wECB.ImmediateAddress, 0xFF, 6 );
  130.     wECB.FragmentDescriptor[0].Address = (char far *)&wPacket;
  131.     wECB.FragmentDescriptor[0].Size = sizeof (IPXPacket );
  132.     wECB.FragmentDescriptor[1].Address = (char far *)&wDataEntity;
  133.     wECB.FragmentDescriptor[1].Size = sizeof( SAPData );
  134.  
  135.     IPXSendPacket( &wECB );
  136.     while( wECB.InUseFlag )
  137.         ;
  138.  
  139.     return (0);
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.